<template>
  <div class="layout">
    <div class="header">
      <div class="left">
        <img :src="icon" alt="icon" class="icon" />
        <span class="name">{{ name }}</span>
        <span class="version">{{ version ? 'v' + version : '' }}</span>
      </div>
      <div class="right">
        <div class="control" title="最小化" @click="minimize"><Minus /></div>
        <div class="control danger" title="关闭" @click="close"><Close /></div>
      </div>
    </div>
    <div class="main">
      <slot></slot>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import icon from '../../../../resources/icon.png'

const minimize = window.api.minimize
const close = window.api.close

const name = ref('')
const version = ref('')

window.api.getName().then((v) => {
  name.value = v
})
window.api.getVersion().then((v) => {
  version.value = v
})
</script>

<style scoped lang="scss">
.layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .header {
    height: 45px;
    background-color: var(--c-background-soft);
    display: flex;
    justify-content: space-between;
    overflow: hidden;
    .left,
    .right {
      display: flex;
      height: 100%;
    }
    .left {
      flex: 1;
      -webkit-app-region: drag;
    }
    .control {
      font-size: 20px;
      color: var(--c-text-2);
      width: 50px;
      height: 45px;
      display: flex;
      justify-content: center;
      align-items: center;
      &:hover {
        background-color: var(--c-hover);
      }
      :deep(svg) {
        width: 1em;
        height: 1em;
      }
      &.danger {
        &:hover {
          background-color: #c42b1c;
        }
      }
    }
    .icon {
      width: 26px;
      height: 26px;
      margin: 9.5px 0 0 9.5px;
    }
    .name {
      font-size: 16px;
      line-height: 45px;
      margin-left: 10px;
    }
    .version {
      font-size: 16px;
      line-height: 45px;
      margin-left: 6px;
    }
  }
  .main {
    flex: 1;
    position: relative;
    overflow: hidden;
  }
}
</style>
